package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.MemberInvoice;
import com.ruoyi.service.IMemberInvoiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 电子发票Controller
 * 
 * @author dongdong
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/parking/memberInvoice")
public class MemberInvoiceController extends BaseController
{
    @Autowired
    private IMemberInvoiceService memberInvoiceService;

    /**
     * 查询电子发票列表
     */
    @PreAuthorize("@ss.hasPermi('parking:memberInvoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberInvoice memberInvoice)
    {
        startPage();
        List<MemberInvoice> list = memberInvoiceService.selectMemberInvoiceList(memberInvoice);
        return getDataTable(list);
    }

    /**
     * 导出电子发票列表
     */
    @PreAuthorize("@ss.hasPermi('parking:memberInvoice:export')")
    @Log(title = "电子发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberInvoice memberInvoice)
    {
        List<MemberInvoice> list = memberInvoiceService.selectMemberInvoiceList(memberInvoice);
        ExcelUtil<MemberInvoice> util = new ExcelUtil<MemberInvoice>(MemberInvoice.class);
        util.exportExcel(response, list, "电子发票数据");
    }

    /**
     * 获取电子发票详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:memberInvoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberInvoiceService.selectMemberInvoiceById(id));
    }

    /**
     * 新增电子发票
     */
    @PreAuthorize("@ss.hasPermi('parking:memberInvoice:add')")
    @Log(title = "电子发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberInvoice memberInvoice)
    {
        return toAjax(memberInvoiceService.insertMemberInvoice(memberInvoice));
    }

    /**
     * 修改电子发票
     */
    @PreAuthorize("@ss.hasPermi('parking:memberInvoice:edit')")
    @Log(title = "电子发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberInvoice memberInvoice)
    {
        return toAjax(memberInvoiceService.updateMemberInvoice(memberInvoice));
    }

    /**
     * 删除电子发票
     */
    @PreAuthorize("@ss.hasPermi('parking:memberInvoice:remove')")
    @Log(title = "电子发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberInvoiceService.deleteMemberInvoiceByIds(ids));
    }

    /**
     * 导出电子发票列表
     */
    @PostMapping("/importInvoiceTemplate")
    public void importInvoiceTemplate(HttpServletResponse response, MemberInvoice memberInvoice)
    {
        List<MemberInvoice> list = memberInvoiceService.selectMemberInvoiceList(memberInvoice);
        ExcelUtil<MemberInvoice> util = new ExcelUtil<MemberInvoice>(MemberInvoice.class);
        util.exportExcel(response, list, "电子发票数据");
    }

    /**
     * 开具电子发票
     */
    @PostMapping("/issueInvoice")
    public AjaxResult issueInvoice(@RequestBody MemberInvoice memberInvoice) {
        return toAjax(memberInvoiceService.issueInvoice(memberInvoice));
    }

}
